﻿#include "vertexitem.h"

VertexItem::VertexItem(QGraphicsItem *parent) :
    QGraphicsItem(parent)
{
    this->setName("vertex");
    this->index = -1;
}

//находим связи
bool VertexItem::isLinkWith(int ind){
    for ( int i=0; i<this->links.size(); i++ ){
        if ( ind == this->links.at(i) ){
            return true;
        }
    }
    return false;
}

int VertexItem::getIndex(){
    return this->index;
}

void VertexItem::setXX(int x){
    this->x = x;
    this->setX(x);
    return;
}
void VertexItem::setYY(int y){
    this->y = y;
    this->setY(y);
    return;
}
void VertexItem::setIndex(int i){
    this->index = i;
    return;
}
void VertexItem::setName(QString name){
    this->name = name;
    return;
}

//добавляем связь, если её нет
void VertexItem::addLink(int link){
    if ( !this->isLinkWith( link ) ){
        this->links.resize( this->links.size() );
        this->links.append( link );
    }
    return;
}

//удаляем связь
void VertexItem::removeLink(int link){

    for ( int i=0; i<this->links.size(); i++ ){
        if ( link == this->links.at(i) ){
            this->links.remove(i);
        }
    }
    return;
}

void VertexItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
   painter->drawRoundedRect(-8, -8, 16, 16, 8, 8);
   painter->drawText( -4,-8,18,18,0, QString("%1").arg(this->index)  );
}


